{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 地图与地理坐标可视化\n",
    "\n",
    "* geo \n",
    "\n",
    "* map\n",
    "\n",
    "* Bmap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import json\n",
    "from pandas.io.json import json_normalize\n",
    "import pyecharts as pe\n",
    "from collections import Counter"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## geo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'china':'https://assets.pyecharts.org/assets/maps/china'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"c0237bedd90d4ee284904be9b0c0f69a\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'china'], function(echarts) {\n",
       "                var chart_c0237bedd90d4ee284904be9b0c0f69a = echarts.init(\n",
       "                    document.getElementById('c0237bedd90d4ee284904be9b0c0f69a'), 'white', {renderer: 'canvas'});\n",
       "                var option_c0237bedd90d4ee284904be9b0c0f69a = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"geo\",\n",
       "            \"coordinateSystem\": \"geo\",\n",
       "            \"symbolSize\": 12,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": [\n",
       "                        113.26653,\n",
       "                        23.132191,\n",
       "                        139\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": [\n",
       "                        116.407526,\n",
       "                        39.90403,\n",
       "                        20\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": [\n",
       "                        121.473701,\n",
       "                        31.230416,\n",
       "                        85\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": [\n",
       "                        115.909228,\n",
       "                        28.675696,\n",
       "                        84\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\",\n",
       "                    \"value\": [\n",
       "                        112.98381,\n",
       "                        28.112444,\n",
       "                        87\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": [\n",
       "                        120.152791,\n",
       "                        30.267446,\n",
       "                        87\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": [\n",
       "                        118.763232,\n",
       "                        32.061707,\n",
       "                        55\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"geo\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"geo\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": function (params) {        return params.name + ' : ' + params.value[2];    },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"Geo-\\u57fa\\u672c\\u793a\\u4f8b\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 100,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true\n",
       "    },\n",
       "    \"geo\": {\n",
       "        \"map\": \"china\",\n",
       "        \"roam\": true,\n",
       "        \"emphasis\": {}\n",
       "    }\n",
       "};\n",
       "                chart_c0237bedd90d4ee284904be9b0c0f69a.setOption(option_c0237bedd90d4ee284904be9b0c0f69a);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x28d1641b2b0>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 官网的案例\n",
    "from pyecharts.faker import Faker\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Geo\n",
    "from pyecharts.globals import ChartType, SymbolType\n",
    "\n",
    "\n",
    "g0 = Geo()\n",
    "g0.add_schema(maptype=\"china\")\n",
    "g0.add(\"geo\", [list(z) for z in zip(Faker.provinces, Faker.values())])\n",
    "g0.set_series_opts(label_opts=opts.LabelOpts(is_show=False))#去掉标识\n",
    "g0.set_global_opts(\n",
    "            visualmap_opts=opts.VisualMapOpts(is_piecewise=True),#显示坐下角的颜色控制\n",
    "            title_opts=opts.TitleOpts(title=\"Geo-基本示例\"),\n",
    "        )\n",
    "g0.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['广东', 42],\n",
       " ['北京', 58],\n",
       " ['上海', 31],\n",
       " ['江西', 108],\n",
       " ['湖南', 36],\n",
       " ['浙江', 130],\n",
       " ['江苏', 139]]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 地图可视化的数据结构\n",
    "[list(z) for z in zip(Faker.provinces, Faker.values())]\n",
    "#注意在pyecharts的后台，中国各个省市的经纬度都是准备好了，不用指定"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 可以通过maptype来选择具体省市的地图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', '浙江':'https://assets.pyecharts.org/assets/maps/zhejiang'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"c04ccc8735904f77814433ad2e597365\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', '浙江'], function(echarts) {\n",
       "                var chart_c04ccc8735904f77814433ad2e597365 = echarts.init(\n",
       "                    document.getElementById('c04ccc8735904f77814433ad2e597365'), 'white', {renderer: 'canvas'});\n",
       "                var option_c04ccc8735904f77814433ad2e597365 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"geo\",\n",
       "            \"coordinateSystem\": \"geo\",\n",
       "            \"symbolSize\": 12,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u676d\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.19,\n",
       "                        30.26,\n",
       "                        50\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b81\\u6ce2\",\n",
       "                    \"value\": [\n",
       "                        121.56,\n",
       "                        29.86,\n",
       "                        30\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e49\\u4e4c\",\n",
       "                    \"value\": [\n",
       "                        120.06,\n",
       "                        29.32,\n",
       "                        20\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8427\\u5c71\",\n",
       "                    \"value\": [\n",
       "                        120.16,\n",
       "                        30.09,\n",
       "                        99\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"geo\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"geo\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": function (params) {        return params.name + ' : ' + params.value[2];    },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"Geo-\\u57fa\\u672c\\u793a\\u4f8b\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 300,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true\n",
       "    },\n",
       "    \"geo\": {\n",
       "        \"map\": \"\\u6d59\\u6c5f\",\n",
       "        \"roam\": true,\n",
       "        \"emphasis\": {}\n",
       "    }\n",
       "};\n",
       "                chart_c04ccc8735904f77814433ad2e597365.setOption(option_c04ccc8735904f77814433ad2e597365);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x28d18aaab00>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g0 = Geo()\n",
    "g0.add_schema(maptype=\"浙江\")#可以通过maptype来选择具体省市的地图\n",
    "g0.add(\"geo\", [[\"杭州\",50],[\"宁波\",30],[\"义乌\",20],[\"萧山\",99]])\n",
    "g0.set_series_opts(label_opts=opts.LabelOpts(is_show=False))#去掉标识\n",
    "g0.set_global_opts(\n",
    "            visualmap_opts=opts.VisualMapOpts(is_piecewise=True,max_=300),\n",
    "            title_opts=opts.TitleOpts(title=\"Geo-基本示例\"),\n",
    "        )\n",
    "g0.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 利用g.add_coordinate画自定义坐标\n",
    "\n",
    "经纬度查询：http://www.gpsspg.com/maps.htm\n",
    "\n",
    "下面案例参考自：https://blog.csdn.net/qq_31362537/article/details/90667814\n",
    "\n",
    "颜色码表：https://www.114la.com/other/rgb.htm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.globals import GeoType"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', '杭州':'https://assets.pyecharts.org/assets/maps/zhe4_jiang1_hang2_zhou1'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"32124b6cfa7745559630d9b33e57c9cf\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', '杭州'], function(echarts) {\n",
       "                var chart_32124b6cfa7745559630d9b33e57c9cf = echarts.init(\n",
       "                    document.getElementById('32124b6cfa7745559630d9b33e57c9cf'), 'white', {renderer: 'canvas'});\n",
       "                var option_32124b6cfa7745559630d9b33e57c9cf = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"coordinateSystem\": \"geo\",\n",
       "            \"symbolSize\": 20,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u676d\\u5dde\\u5e08\\u8303\\u5927\\u5b66\\u4ed3\\u524d\\u6821\\u533a\",\n",
       "                    \"value\": [\n",
       "                        120.0109472358,\n",
       "                        30.291037372,\n",
       "                        100\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8427\\u5c71\\u57ce\\u53a2\\u8857\\u9053\",\n",
       "                    \"value\": [\n",
       "                        120.274008117,\n",
       "                        30.1605364542,\n",
       "                        500\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u676d\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.19,\n",
       "                        30.26,\n",
       "                        50\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": function (params) {        return params.name + ' : ' + params.value[2];    },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u676d\\u5dde-\\u5e97\\u94fa\\u5206\\u5e03\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 800,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true\n",
       "    },\n",
       "    \"geo\": {\n",
       "        \"map\": \"\\u676d\\u5dde\",\n",
       "        \"roam\": true,\n",
       "        \"emphasis\": {}\n",
       "    }\n",
       "};\n",
       "                chart_32124b6cfa7745559630d9b33e57c9cf.setOption(option_32124b6cfa7745559630d9b33e57c9cf);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x28d18afc748>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city = '杭州'\n",
    "g = Geo()\n",
    "g.add_schema(maptype=city)\n",
    "\n",
    "g.add_coordinate('杭州师范大学仓前校区',120.0109472358, 30.2910373720)#注意这里要求经度在前维度在后\n",
    "g.add_coordinate('萧山城厢街道',120.2740081170, 30.1605364542)\n",
    "\n",
    "data_pair = [('杭州师范大学仓前校区', 100),('萧山城厢街道', 500),(\"杭州\",50)]\n",
    "\n",
    "\n",
    "g.add('', data_pair,symbol_size=20)\n",
    "\n",
    "#  is_piecewise 是否自定义分段， 变为true 才能生效\n",
    "g.set_global_opts(\n",
    "        visualmap_opts=opts.VisualMapOpts(is_piecewise=True,max_=800),#注意默认max_\n",
    "        title_opts=opts.TitleOpts(title=\"{}-店铺分布\".format(city)),\n",
    "    )\n",
    "\n",
    "g.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', '杭州':'https://assets.pyecharts.org/assets/maps/zhe4_jiang1_hang2_zhou1'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"86336d0f9d6d467a932ffbaab4c60c9d\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', '杭州'], function(echarts) {\n",
       "                var chart_86336d0f9d6d467a932ffbaab4c60c9d = echarts.init(\n",
       "                    document.getElementById('86336d0f9d6d467a932ffbaab4c60c9d'), 'white', {renderer: 'canvas'});\n",
       "                var option_86336d0f9d6d467a932ffbaab4c60c9d = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"effectScatter\",\n",
       "            \"coordinateSystem\": \"geo\",\n",
       "            \"showEffectOn\": \"render\",\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            },\n",
       "            \"symbolSize\": 15,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u676d\\u5dde\\u5e08\\u8303\\u5927\\u5b66\\u4ed3\\u524d\\u6821\\u533a\",\n",
       "                    \"value\": [\n",
       "                        120.0109472358,\n",
       "                        30.291037372,\n",
       "                        10\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8427\\u5c71\\u57ce\\u53a2\\u8857\\u9053\",\n",
       "                    \"value\": [\n",
       "                        120.274008117,\n",
       "                        30.1605364542,\n",
       "                        5\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u676d\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.19,\n",
       "                        30.26,\n",
       "                        50\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": function (params) {        return params.name + ' : ' + params.value[2];    },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u676d\\u5dde-\\u5e97\\u94fa\\u5206\\u5e03\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 100,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true,\n",
       "        \"pieces\": [\n",
       "            {\n",
       "                \"max\": 6,\n",
       "                \"label\": \"5\\u4ee5\\u4e0b\",\n",
       "                \"color\": \"#FF00FF\"\n",
       "            },\n",
       "            {\n",
       "                \"min\": 6,\n",
       "                \"max\": 10,\n",
       "                \"label\": \"5-10\",\n",
       "                \"color\": \"yellow\"\n",
       "            },\n",
       "            {\n",
       "                \"min\": 10,\n",
       "                \"max\": 100,\n",
       "                \"label\": \"10-100\",\n",
       "                \"color\": \"red\"\n",
       "            }\n",
       "        ]\n",
       "    },\n",
       "    \"geo\": {\n",
       "        \"map\": \"\\u676d\\u5dde\",\n",
       "        \"roam\": true,\n",
       "        \"emphasis\": {}\n",
       "    }\n",
       "};\n",
       "                chart_86336d0f9d6d467a932ffbaab4c60c9d.setOption(option_86336d0f9d6d467a932ffbaab4c60c9d);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x28d18b5fbe0>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city = '杭州'\n",
    "g = Geo()\n",
    "g.add_schema(maptype=city)\n",
    "# 定义坐标对应的名称，添加到坐标库中 add_coordinate(name, lng, lat)\n",
    "g.add_coordinate('杭州师范大学仓前校区',120.0109472358, 30.2910373720)#注意这里要求经度在前维度在后\n",
    "g.add_coordinate('萧山城厢街道',120.2740081170, 30.1605364542)\n",
    "# 定义数据对\n",
    "data_pair = [('杭州师范大学仓前校区', 10),('萧山城厢街道', 5),(\"杭州\",50)]\n",
    "\n",
    "# Geo 图类型，有 scatter, effectScatter, heatmap, lines 4 种，建议使用\n",
    "# from pyecharts.globals import GeoType\n",
    "# GeoType.GeoType.EFFECT_SCATTER，GeoType.HEATMAP，GeoType.LINES\n",
    "# 将数据添加到地图上\n",
    "g.add('', data_pair, type_=GeoType.EFFECT_SCATTER, symbol_size=15)\n",
    "# 设置样式\n",
    "g.set_series_opts(label_opts=opts.LabelOpts(is_show=False))\n",
    "\n",
    "# 自定义分段 color 可以用取色器取色\n",
    "pieces = [\n",
    "        {'max': 6, 'label': '5以下', 'color': '#FF00FF'},\n",
    "        {'min': 6, 'max': 10, 'label': '5-10', 'color': 'yellow'},\n",
    "        {'min': 10, 'max': 100, 'label': '10-100', 'color': 'red'} # 有下限无上限\n",
    "    ]\n",
    "#  is_piecewise 是否自定义分段， 变为true 才能生效\n",
    "g.set_global_opts(\n",
    "        visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=pieces),#注意默认max_\n",
    "        title_opts=opts.TitleOpts(title=\"{}-店铺分布\".format(city)),\n",
    "    )\n",
    "\n",
    "g.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课间题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 1，引入shoes数据，根据如下步骤作图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "op1=open(r'D:\\try\\shoes.json', 'r',encoding='utf-8')\n",
    "li=[]\n",
    "dict1={}\n",
    "for i in op1:\n",
    "    k=json.loads(i.encode(\"utf-8\"))#把字符串转换为json\n",
    "    li.append(k)\n",
    "a=json_normalize(li)#把由json数据构成的列表转换成数据框"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>_id.$oid</th>\n",
       "      <th>info.上市年份季节</th>\n",
       "      <th>info.上市时间</th>\n",
       "      <th>info.产品名称</th>\n",
       "      <th>info.低帮鞋品名</th>\n",
       "      <th>info.功能</th>\n",
       "      <th>info.吊牌价</th>\n",
       "      <th>info.品牌</th>\n",
       "      <th>info.图案</th>\n",
       "      <th>info.场合</th>\n",
       "      <th>...</th>\n",
       "      <th>info.鞋面材质</th>\n",
       "      <th>info.颜色分类</th>\n",
       "      <th>info.风格</th>\n",
       "      <th>itemid</th>\n",
       "      <th>location</th>\n",
       "      <th>nick</th>\n",
       "      <th>price</th>\n",
       "      <th>sales</th>\n",
       "      <th>title</th>\n",
       "      <th>url</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5aa77041be9b0338dc1faab4</td>\n",
       "      <td>2018年春季</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>商务休闲鞋</td>\n",
       "      <td>轻质</td>\n",
       "      <td>NaN</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>日常</td>\n",
       "      <td>...</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色土黄</td>\n",
       "      <td>商务</td>\n",
       "      <td>562121114807</td>\n",
       "      <td>浙江 丽水</td>\n",
       "      <td>意尔康皮鞋旗舰店</td>\n",
       "      <td>269.00</td>\n",
       "      <td>1583人付款</td>\n",
       "      <td>意尔康男鞋2018春季新款英伦真皮商务休闲皮鞋青年男士皮鞋子男潮</td>\n",
       "      <td>http://detail.tmall.com/item.htm?id=5621211148...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5aa77042be9b0338dc1faab5</td>\n",
       "      <td>2017年秋季</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>商务休闲鞋</td>\n",
       "      <td>轻质</td>\n",
       "      <td>NaN</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>办公室</td>\n",
       "      <td>...</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色棕色黑色加绒版棕色加绒版黑色镂空棕色镂空</td>\n",
       "      <td>商务</td>\n",
       "      <td>545941839337</td>\n",
       "      <td>浙江 丽水</td>\n",
       "      <td>意尔康皮鞋旗舰店</td>\n",
       "      <td>199.00</td>\n",
       "      <td>1607人付款</td>\n",
       "      <td>意尔康旗舰店官方店男鞋春秋真皮爸爸鞋中老年人商务休闲皮鞋子男</td>\n",
       "      <td>http://detail.tmall.com/item.htm?id=5459418393...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5aa77042be9b0338dc1faab6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>透气</td>\n",
       "      <td>NaN</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>办公室</td>\n",
       "      <td>...</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色</td>\n",
       "      <td>商务</td>\n",
       "      <td>563340844728</td>\n",
       "      <td>浙江 温州</td>\n",
       "      <td>吸引力xl</td>\n",
       "      <td>148.00</td>\n",
       "      <td>248人付款</td>\n",
       "      <td>2017新款正品意尔康男鞋男士商务正装皮鞋透气真皮系带尖头办公室</td>\n",
       "      <td>http://item.taobao.com/item.htm?id=56334084472...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5aa77042be9b0338dc1faab7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>透气</td>\n",
       "      <td>NaN</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>日常</td>\n",
       "      <td>...</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色真皮 棕色真皮 黑色加绒真皮 棕色加绒真皮</td>\n",
       "      <td>商务</td>\n",
       "      <td>561684297836</td>\n",
       "      <td>浙江 温州</td>\n",
       "      <td>乙方乙方88888</td>\n",
       "      <td>158.00</td>\n",
       "      <td>195人付款</td>\n",
       "      <td>皮鞋男正品意尔康休闲商务真皮一脚蹬爸爸鞋春季新款圆头透气男鞋</td>\n",
       "      <td>http://item.taobao.com/item.htm?id=56168429783...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5aa77042be9b0338dc1faab8</td>\n",
       "      <td>2017年秋季</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>休闲皮鞋</td>\n",
       "      <td>耐磨</td>\n",
       "      <td>NaN</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>日常</td>\n",
       "      <td>...</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色单鞋土黄单鞋</td>\n",
       "      <td>休闲</td>\n",
       "      <td>555004335522</td>\n",
       "      <td>浙江 丽水</td>\n",
       "      <td>意尔康男鞋旗舰店</td>\n",
       "      <td>279.00</td>\n",
       "      <td>37人付款</td>\n",
       "      <td>意尔康男鞋2018春季真皮套脚休闲鞋潮流新款舒适一脚蹬单鞋皮鞋</td>\n",
       "      <td>http://detail.tmall.com/item.htm?id=5550043355...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 52 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                   _id.$oid info.上市年份季节 info.上市时间 info.产品名称 info.低帮鞋品名  \\\n",
       "0  5aa77041be9b0338dc1faab4     2018年春季       NaN       NaN      商务休闲鞋   \n",
       "1  5aa77042be9b0338dc1faab5     2017年秋季       NaN       NaN      商务休闲鞋   \n",
       "2  5aa77042be9b0338dc1faab6         NaN       NaN       NaN        NaN   \n",
       "3  5aa77042be9b0338dc1faab7         NaN       NaN       NaN        NaN   \n",
       "4  5aa77042be9b0338dc1faab8     2017年秋季       NaN       NaN       休闲皮鞋   \n",
       "\n",
       "  info.功能 info.吊牌价      info.品牌 info.图案 info.场合  \\\n",
       "0      轻质      NaN  YEARCON/意尔康      纯色      日常   \n",
       "1      轻质      NaN  YEARCON/意尔康      纯色     办公室   \n",
       "2      透气      NaN  YEARCON/意尔康      纯色     办公室   \n",
       "3      透气      NaN  YEARCON/意尔康      纯色      日常   \n",
       "4      耐磨      NaN  YEARCON/意尔康      纯色      日常   \n",
       "\n",
       "                         ...                           info.鞋面材质  \\\n",
       "0                        ...                          头层牛皮（除牛反绒）   \n",
       "1                        ...                          头层牛皮（除牛反绒）   \n",
       "2                        ...                          头层牛皮（除牛反绒）   \n",
       "3                        ...                          头层牛皮（除牛反绒）   \n",
       "4                        ...                          头层牛皮（除牛反绒）   \n",
       "\n",
       "                 info.颜色分类 info.风格        itemid location       nick   price  \\\n",
       "0                     黑色土黄      商务  562121114807    浙江 丽水   意尔康皮鞋旗舰店  269.00   \n",
       "1   黑色棕色黑色加绒版棕色加绒版黑色镂空棕色镂空      商务  545941839337    浙江 丽水   意尔康皮鞋旗舰店  199.00   \n",
       "2                       黑色      商务  563340844728    浙江 温州      吸引力xl  148.00   \n",
       "3  黑色真皮 棕色真皮 黑色加绒真皮 棕色加绒真皮      商务  561684297836    浙江 温州  乙方乙方88888  158.00   \n",
       "4                 黑色单鞋土黄单鞋      休闲  555004335522    浙江 丽水   意尔康男鞋旗舰店  279.00   \n",
       "\n",
       "     sales                             title  \\\n",
       "0  1583人付款  意尔康男鞋2018春季新款英伦真皮商务休闲皮鞋青年男士皮鞋子男潮   \n",
       "1  1607人付款    意尔康旗舰店官方店男鞋春秋真皮爸爸鞋中老年人商务休闲皮鞋子男   \n",
       "2   248人付款  2017新款正品意尔康男鞋男士商务正装皮鞋透气真皮系带尖头办公室   \n",
       "3   195人付款    皮鞋男正品意尔康休闲商务真皮一脚蹬爸爸鞋春季新款圆头透气男鞋   \n",
       "4    37人付款   意尔康男鞋2018春季真皮套脚休闲鞋潮流新款舒适一脚蹬单鞋皮鞋   \n",
       "\n",
       "                                                 url  \n",
       "0  http://detail.tmall.com/item.htm?id=5621211148...  \n",
       "1  http://detail.tmall.com/item.htm?id=5459418393...  \n",
       "2  http://item.taobao.com/item.htm?id=56334084472...  \n",
       "3  http://item.taobao.com/item.htm?id=56168429783...  \n",
       "4  http://detail.tmall.com/item.htm?id=5550043355...  \n",
       "\n",
       "[5 rows x 52 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "#a.location.str.split(\" \",expand=True)[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "sheng=a.location.str.split(\" \",expand=True)[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    浙江\n",
       "1    浙江\n",
       "2    浙江\n",
       "3    浙江\n",
       "4    浙江\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 提取出location中省与直辖市\n",
    "sheng.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 以省与直辖市序列做groupby，求出各个省与直辖市的商品数量\n",
    "p0=a.groupby(sheng).size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0\n",
       "上海     154\n",
       "北京     339\n",
       "吉林       1\n",
       "四川       4\n",
       "安徽      24\n",
       "山东      44\n",
       "山西      39\n",
       "广东     284\n",
       "江苏     120\n",
       "江西      42\n",
       "河北      86\n",
       "河南     393\n",
       "浙江    2470\n",
       "湖北      27\n",
       "福建     952\n",
       "贵州       2\n",
       "辽宁       3\n",
       "重庆       3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<zip at 0x2156ea68fc8>"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p0.items()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0\n",
       "上海     154\n",
       "北京     339\n",
       "吉林       1\n",
       "四川       4\n",
       "安徽      24\n",
       "山东      44\n",
       "山西      39\n",
       "广东     284\n",
       "江苏     120\n",
       "江西      42\n",
       "河北      86\n",
       "河南     393\n",
       "浙江    2470\n",
       "湖北      27\n",
       "福建     952\n",
       "贵州       2\n",
       "辽宁       3\n",
       "重庆       3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('上海', 154),\n",
       " ('北京', 339),\n",
       " ('吉林', 1),\n",
       " ('四川', 4),\n",
       " ('安徽', 24),\n",
       " ('山东', 44),\n",
       " ('山西', 39),\n",
       " ('广东', 284),\n",
       " ('江苏', 120),\n",
       " ('江西', 42),\n",
       " ('河北', 86),\n",
       " ('河南', 393),\n",
       " ('浙江', 2470),\n",
       " ('湖北', 27),\n",
       " ('福建', 952),\n",
       " ('贵州', 2),\n",
       " ('辽宁', 3),\n",
       " ('重庆', 3)]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 把数据处理成地图需要的格式\n",
    "[z for z in p0.items()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'china':'https://assets.pyecharts.org/assets/maps/china'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"348c95792fa44f1fa15c60c0871da223\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'china'], function(echarts) {\n",
       "                var chart_348c95792fa44f1fa15c60c0871da223 = echarts.init(\n",
       "                    document.getElementById('348c95792fa44f1fa15c60c0871da223'), 'white', {renderer: 'canvas'});\n",
       "                var option_348c95792fa44f1fa15c60c0871da223 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"geo\",\n",
       "            \"coordinateSystem\": \"geo\",\n",
       "            \"symbolSize\": 12,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": [\n",
       "                        121.473701,\n",
       "                        31.230416,\n",
       "                        154\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": [\n",
       "                        116.407526,\n",
       "                        39.90403,\n",
       "                        339\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5409\\u6797\",\n",
       "                    \"value\": [\n",
       "                        125.32599,\n",
       "                        43.896536,\n",
       "                        1\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u56db\\u5ddd\",\n",
       "                    \"value\": [\n",
       "                        104.075931,\n",
       "                        30.651651,\n",
       "                        4\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b89\\u5fbd\",\n",
       "                    \"value\": [\n",
       "                        117.284922,\n",
       "                        31.861184,\n",
       "                        24\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u4e1c\",\n",
       "                    \"value\": [\n",
       "                        117.020359,\n",
       "                        36.66853,\n",
       "                        44\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u897f\",\n",
       "                    \"value\": [\n",
       "                        112.562398,\n",
       "                        37.873531,\n",
       "                        39\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": [\n",
       "                        113.26653,\n",
       "                        23.132191,\n",
       "                        284\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": [\n",
       "                        118.763232,\n",
       "                        32.061707,\n",
       "                        120\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": [\n",
       "                        115.909228,\n",
       "                        28.675696,\n",
       "                        42\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\",\n",
       "                    \"value\": [\n",
       "                        114.468664,\n",
       "                        38.037057,\n",
       "                        86\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5357\",\n",
       "                    \"value\": [\n",
       "                        113.753602,\n",
       "                        34.765515,\n",
       "                        393\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": [\n",
       "                        120.152791,\n",
       "                        30.267446,\n",
       "                        2470\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5317\",\n",
       "                    \"value\": [\n",
       "                        114.341861,\n",
       "                        30.546498,\n",
       "                        27\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u798f\\u5efa\",\n",
       "                    \"value\": [\n",
       "                        119.295144,\n",
       "                        26.100779,\n",
       "                        952\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d35\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        106.70741,\n",
       "                        26.598194,\n",
       "                        2\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8fbd\\u5b81\",\n",
       "                    \"value\": [\n",
       "                        123.42944,\n",
       "                        41.835441,\n",
       "                        3\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91cd\\u5e86\",\n",
       "                    \"value\": [\n",
       "                        106.551556,\n",
       "                        29.563009,\n",
       "                        3\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"geo\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"geo\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": function (params) {        return params.name + ' : ' + params.value[2];    },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u5546\\u54c1\\u5168\\u56fd\\u5206\\u5e03\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 3000,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true\n",
       "    },\n",
       "    \"geo\": {\n",
       "        \"map\": \"china\",\n",
       "        \"roam\": true,\n",
       "        \"emphasis\": {}\n",
       "    }\n",
       "};\n",
       "                chart_348c95792fa44f1fa15c60c0871da223.setOption(option_348c95792fa44f1fa15c60c0871da223);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x28d18b52320>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 画出商品数量全国分布图\n",
    "g0 = Geo()\n",
    "g0.add_schema(maptype=\"china\")\n",
    "g0.add(\"geo\", [z for z in p0.items()])\n",
    "g0.set_series_opts(label_opts=opts.LabelOpts(is_show=False))#去掉标识\n",
    "\n",
    "g0.set_global_opts(\n",
    "            visualmap_opts=opts.VisualMapOpts(is_piecewise=True,max_=3000),\n",
    "            title_opts=opts.TitleOpts(title=\"商品全国分布\"),\n",
    "        )\n",
    "g0.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 2 画出你家乡城市的地图，通过自定义坐标点，在家乡城市地图上画出你的家，小学，中学的位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 3 按照如下步骤画出浙江省各个地市的商品分布图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "#a.location.str.split(\" \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       丽水\n",
       "1       丽水\n",
       "2       温州\n",
       "3       温州\n",
       "4       丽水\n",
       "5       温州\n",
       "6       温州\n",
       "7       温州\n",
       "8       丽水\n",
       "10      丽水\n",
       "11      温州\n",
       "12      丽水\n",
       "13      温州\n",
       "14      温州\n",
       "15      温州\n",
       "16      杭州\n",
       "17      温岭\n",
       "18      丽水\n",
       "20      杭州\n",
       "21      温州\n",
       "22      温州\n",
       "24      温州\n",
       "25      温州\n",
       "26      杭州\n",
       "27      丽水\n",
       "28      丽水\n",
       "29      温州\n",
       "30      温州\n",
       "31      丽水\n",
       "34      温州\n",
       "        ..\n",
       "4883    温州\n",
       "4893    温州\n",
       "4894    温州\n",
       "4899    温州\n",
       "4900    温州\n",
       "4903    温州\n",
       "4904    温州\n",
       "4905    温州\n",
       "4906    嘉兴\n",
       "4911    温州\n",
       "4921    温州\n",
       "4922    温州\n",
       "4925    温州\n",
       "4927    温州\n",
       "4929    温州\n",
       "4931    温州\n",
       "4943    温州\n",
       "4944    温州\n",
       "4945    温州\n",
       "4947    温州\n",
       "4948    温州\n",
       "4949    温州\n",
       "4950    温州\n",
       "4953    温州\n",
       "4954    温州\n",
       "4958    温州\n",
       "4960    温州\n",
       "4961    温州\n",
       "4964    温州\n",
       "4965    温州\n",
       "Length: 2470, dtype: object"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#把数据中所有浙江省的商品都挑出来，并以浙江的地市作为值形成一个新的序列\n",
    "k=0\n",
    "zj={}\n",
    "for i in a.location.str.split(\" \").items():\n",
    "    if i[1][0]==\"浙江\":\n",
    "        zj.update({i[0]:i[1][1]})\n",
    "zj=pd.Series(zj)\n",
    "zj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "丽水     938\n",
       "台州       2\n",
       "嘉兴       4\n",
       "宁波       8\n",
       "杭州     107\n",
       "温岭      10\n",
       "温州    1275\n",
       "湖州     118\n",
       "绍兴       1\n",
       "衢州       3\n",
       "金华       4\n",
       "dtype: int64"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求出浙江省各个地市的商品数\n",
    "p1=a.groupby(zj).size()\n",
    "p1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', '浙江':'https://assets.pyecharts.org/assets/maps/zhejiang'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"b67a69e5583249898f562d1e229e49a3\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', '浙江'], function(echarts) {\n",
       "                var chart_b67a69e5583249898f562d1e229e49a3 = echarts.init(\n",
       "                    document.getElementById('b67a69e5583249898f562d1e229e49a3'), 'white', {renderer: 'canvas'});\n",
       "                var option_b67a69e5583249898f562d1e229e49a3 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"geo\",\n",
       "            \"coordinateSystem\": \"geo\",\n",
       "            \"symbolSize\": 12,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u4e3d\\u6c34\",\n",
       "                    \"value\": [\n",
       "                        119.92,\n",
       "                        28.45,\n",
       "                        938\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u53f0\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        121.420757,\n",
       "                        28.656386,\n",
       "                        2\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5609\\u5174\",\n",
       "                    \"value\": [\n",
       "                        120.76,\n",
       "                        30.77,\n",
       "                        4\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b81\\u6ce2\",\n",
       "                    \"value\": [\n",
       "                        121.56,\n",
       "                        29.86,\n",
       "                        8\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u676d\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.19,\n",
       "                        30.26,\n",
       "                        107\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e29\\u5cad\",\n",
       "                    \"value\": [\n",
       "                        121.21,\n",
       "                        28.22,\n",
       "                        10\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e29\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.65,\n",
       "                        28.01,\n",
       "                        1275\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.1,\n",
       "                        30.86,\n",
       "                        118\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7ecd\\u5174\",\n",
       "                    \"value\": [\n",
       "                        120.58,\n",
       "                        30.01,\n",
       "                        1\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8862\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        118.88,\n",
       "                        28.97,\n",
       "                        3\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91d1\\u534e\",\n",
       "                    \"value\": [\n",
       "                        119.64,\n",
       "                        29.12,\n",
       "                        4\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"geo\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"geo\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": function (params) {        return params.name + ' : ' + params.value[2];    },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6d59\\u6c5f\\u5546\\u54c1\\u5206\\u5e03\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 2000,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true\n",
       "    },\n",
       "    \"geo\": {\n",
       "        \"map\": \"\\u6d59\\u6c5f\",\n",
       "        \"roam\": true,\n",
       "        \"emphasis\": {}\n",
       "    }\n",
       "};\n",
       "                chart_b67a69e5583249898f562d1e229e49a3.setOption(option_b67a69e5583249898f562d1e229e49a3);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x204b769de80>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g0 = Geo()\n",
    "g0.add_schema(maptype=\"浙江\")\n",
    "g0.add(\"geo\", [z for z in p1.items()])\n",
    "g0.set_series_opts(label_opts=opts.LabelOpts(is_show=False))#去掉标识\n",
    "\n",
    "g0.set_global_opts(\n",
    "            visualmap_opts=opts.VisualMapOpts(is_piecewise=True,max_=2000),\n",
    "            title_opts=opts.TitleOpts(title=\"浙江商品分布\"),\n",
    "        )\n",
    "g0.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', '浙江':'https://assets.pyecharts.org/assets/maps/zhejiang'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"55e6c6e568f545e08cd51f24c6f2fc6e\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', '浙江'], function(echarts) {\n",
       "                var chart_55e6c6e568f545e08cd51f24c6f2fc6e = echarts.init(\n",
       "                    document.getElementById('55e6c6e568f545e08cd51f24c6f2fc6e'), 'white', {renderer: 'canvas'});\n",
       "                var option_55e6c6e568f545e08cd51f24c6f2fc6e = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"heatmap\",\n",
       "            \"name\": \"geo\",\n",
       "            \"coordinateSystem\": \"geo\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u4e3d\\u6c34\",\n",
       "                    \"value\": [\n",
       "                        119.92,\n",
       "                        28.45,\n",
       "                        938\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u53f0\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        121.420757,\n",
       "                        28.656386,\n",
       "                        2\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5609\\u5174\",\n",
       "                    \"value\": [\n",
       "                        120.76,\n",
       "                        30.77,\n",
       "                        4\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b81\\u6ce2\",\n",
       "                    \"value\": [\n",
       "                        121.56,\n",
       "                        29.86,\n",
       "                        8\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u676d\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.19,\n",
       "                        30.26,\n",
       "                        107\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e29\\u5cad\",\n",
       "                    \"value\": [\n",
       "                        121.21,\n",
       "                        28.22,\n",
       "                        10\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e29\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.65,\n",
       "                        28.01,\n",
       "                        1275\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.1,\n",
       "                        30.86,\n",
       "                        118\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7ecd\\u5174\",\n",
       "                    \"value\": [\n",
       "                        120.58,\n",
       "                        30.01,\n",
       "                        1\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8862\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        118.88,\n",
       "                        28.97,\n",
       "                        3\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91d1\\u534e\",\n",
       "                    \"value\": [\n",
       "                        119.64,\n",
       "                        29.12,\n",
       "                        4\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"pointSize\": 20,\n",
       "            \"blurSize\": 20,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"geo\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"geo\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": function (params) {        return params.name + ' : ' + params.value[2];    },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6d59\\u6c5f\\u5546\\u54c1\\u5206\\u5e03\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 100,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true,\n",
       "        \"pieces\": [\n",
       "            {\n",
       "                \"max\": 100,\n",
       "                \"label\": \"100\\u4ee5\\u4e0b\",\n",
       "                \"color\": \"#FFDEAD\"\n",
       "            },\n",
       "            {\n",
       "                \"min\": 100,\n",
       "                \"max\": 1000,\n",
       "                \"label\": \"100-1000\",\n",
       "                \"color\": \"#FFA54F\"\n",
       "            },\n",
       "            {\n",
       "                \"min\": 1000,\n",
       "                \"max\": 3000,\n",
       "                \"label\": \"1000-3000\",\n",
       "                \"color\": \"#FF3030\"\n",
       "            }\n",
       "        ]\n",
       "    },\n",
       "    \"geo\": {\n",
       "        \"map\": \"\\u6d59\\u6c5f\",\n",
       "        \"roam\": true,\n",
       "        \"emphasis\": {}\n",
       "    }\n",
       "};\n",
       "                chart_55e6c6e568f545e08cd51f24c6f2fc6e.setOption(option_55e6c6e568f545e08cd51f24c6f2fc6e);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x204b3505710>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g0 = Geo()\n",
    "g0.add_schema(maptype=\"浙江\")\n",
    "g0.add(\"geo\", [z for z in p1.items()],type_=ChartType.HEATMAP)\n",
    "g0.set_series_opts(label_opts=opts.LabelOpts(is_show=False))#去掉标识\n",
    "\n",
    "pieces = [\n",
    "        {'max': 100, 'label': '100以下', 'color': '#FFDEAD'},\n",
    "        {'min': 100, 'max': 1000, 'label': '100-1000', 'color': '#FFA54F'},\n",
    "        {'min': 1000, 'max': 3000, 'label': '1000-3000', 'color': '#FF3030'} # 有下限无上限\n",
    "    ]\n",
    "\n",
    "g0.set_global_opts(\n",
    "            visualmap_opts=opts.VisualMapOpts(is_piecewise=True,pieces=pieces),\n",
    "            title_opts=opts.TitleOpts(title=\"浙江商品分布\"),\n",
    "        )\n",
    "g0.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## map作图\n",
    "\n",
    "* map的功能和geo有不少重合，区别在于可以显示地图区域块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['广东', 25],\n",
       " ['北京', 94],\n",
       " ['上海', 68],\n",
       " ['江西', 31],\n",
       " ['湖南', 44],\n",
       " ['浙江', 104],\n",
       " ['江苏', 89]]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[list(z) for z in zip(Faker.provinces, Faker.values())]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'china':'https://assets.pyecharts.org/assets/maps/china'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"e3afd0cd4433464f92ebca4189213dd2\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'china'], function(echarts) {\n",
       "                var chart_e3afd0cd4433464f92ebca4189213dd2 = echarts.init(\n",
       "                    document.getElementById('e3afd0cd4433464f92ebca4189213dd2'), 'white', {renderer: 'canvas'});\n",
       "                var option_e3afd0cd4433464f92ebca4189213dd2 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"\\u5546\\u5bb6A\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"china\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": 150\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": 49\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": 107\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": 55\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\",\n",
       "                    \"value\": 76\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": 123\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": 31\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"zoom\": 1,\n",
       "            \"showLegendSymbol\": true,\n",
       "            \"emphasis\": {}\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5546\\u5bb6A\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u5546\\u5bb6A\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"Map-VisualMap\\uff08\\u5206\\u6bb5\\u578b\\uff09\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 200,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true\n",
       "    }\n",
       "};\n",
       "                chart_e3afd0cd4433464f92ebca4189213dd2.setOption(option_e3afd0cd4433464f92ebca4189213dd2);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x28d18b52128>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m1=Map()\n",
    "m1.add(\"商家A\", [list(z) for z in zip(Faker.provinces, Faker.values())], \"china\")\n",
    "m1.set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"Map-VisualMap（分段型）\"),\n",
    "            visualmap_opts=opts.VisualMapOpts(max_=200, is_piecewise=True),\n",
    "        )\n",
    "m1.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课间题\n",
    "\n",
    "* 用map做出男鞋商品全国省分布图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'china':'https://assets.pyecharts.org/assets/maps/china'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"ed1637a5beb84410b327a30b0d464687\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'china'], function(echarts) {\n",
       "                var chart_ed1637a5beb84410b327a30b0d464687 = echarts.init(\n",
       "                    document.getElementById('ed1637a5beb84410b327a30b0d464687'), 'white', {renderer: 'canvas'});\n",
       "                var option_ed1637a5beb84410b327a30b0d464687 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"\\u5546\\u5bb6A\",\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"china\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": 154\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": 339\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5409\\u6797\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u56db\\u5ddd\",\n",
       "                    \"value\": 4\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b89\\u5fbd\",\n",
       "                    \"value\": 24\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u4e1c\",\n",
       "                    \"value\": 44\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u897f\",\n",
       "                    \"value\": 39\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": 284\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": 120\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": 42\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\",\n",
       "                    \"value\": 86\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5357\",\n",
       "                    \"value\": 393\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": 2470\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5317\",\n",
       "                    \"value\": 27\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u798f\\u5efa\",\n",
       "                    \"value\": 952\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d35\\u5dde\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8fbd\\u5b81\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91cd\\u5e86\",\n",
       "                    \"value\": 3\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"zoom\": 1,\n",
       "            \"showLegendSymbol\": false,\n",
       "            \"emphasis\": {},\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5546\\u5bb6A\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u5546\\u5bb6A\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"Map-VisualMap\\uff08\\u5206\\u6bb5\\u578b\\uff09\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 3000,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true\n",
       "    }\n",
       "};\n",
       "                chart_ed1637a5beb84410b327a30b0d464687.setOption(option_ed1637a5beb84410b327a30b0d464687);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x2bba2c8f0b8>"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m1=Map()\n",
    "m1.add(\"商家A\", [z for z in p0.items()], \"china\",is_map_symbol_show=False)\n",
    "m1.set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"Map-VisualMap（分段型）\"),\n",
    "            visualmap_opts=opts.VisualMapOpts(max_=3000, is_piecewise=True),\n",
    "        )\n",
    "m1.set_series_opts(label_opts=opts.LabelOpts(is_show=False))\n",
    "m1.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 做出浙江省地级市商品分布图(注意这里的城市名后面要加\"市\"，比如丽水市)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('丽水', 938),\n",
       " ('台州', 2),\n",
       " ('嘉兴', 4),\n",
       " ('宁波', 8),\n",
       " ('杭州', 107),\n",
       " ('温岭', 10),\n",
       " ('温州', 1275),\n",
       " ('湖州', 118),\n",
       " ('绍兴', 1),\n",
       " ('衢州', 3),\n",
       " ('金华', 4)]"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[z for z in p1.items()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "data=[]\n",
    "for i in p1.items():\n",
    "    data.append([i[0]+\"市\",i[1]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['丽水市', 938],\n",
       " ['台州市', 2],\n",
       " ['嘉兴市', 4],\n",
       " ['宁波市', 8],\n",
       " ['杭州市', 107],\n",
       " ['温岭市', 10],\n",
       " ['温州市', 1275],\n",
       " ['湖州市', 118],\n",
       " ['绍兴市', 1],\n",
       " ['衢州市', 3],\n",
       " ['金华市', 4]]"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', '浙江':'https://assets.pyecharts.org/assets/maps/zhejiang'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"feac788f158a4da09eae1076ca4fe21a\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', '浙江'], function(echarts) {\n",
       "                var chart_feac788f158a4da09eae1076ca4fe21a = echarts.init(\n",
       "                    document.getElementById('feac788f158a4da09eae1076ca4fe21a'), 'white', {renderer: 'canvas'});\n",
       "                var option_feac788f158a4da09eae1076ca4fe21a = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"\\u5546\\u5bb6A\",\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"\\u6d59\\u6c5f\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u4e3d\\u6c34\\u5e02\",\n",
       "                    \"value\": 938\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u53f0\\u5dde\\u5e02\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5609\\u5174\\u5e02\",\n",
       "                    \"value\": 4\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b81\\u6ce2\\u5e02\",\n",
       "                    \"value\": 8\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u676d\\u5dde\\u5e02\",\n",
       "                    \"value\": 107\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e29\\u5cad\\u5e02\",\n",
       "                    \"value\": 10\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e29\\u5dde\\u5e02\",\n",
       "                    \"value\": 1275\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5dde\\u5e02\",\n",
       "                    \"value\": 118\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7ecd\\u5174\\u5e02\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8862\\u5dde\\u5e02\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91d1\\u534e\\u5e02\",\n",
       "                    \"value\": 4\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"zoom\": 1,\n",
       "            \"showLegendSymbol\": false,\n",
       "            \"emphasis\": {},\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5546\\u5bb6A\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u5546\\u5bb6A\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"Map-VisualMap\\uff08\\u5206\\u6bb5\\u578b\\uff09\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 3000,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true\n",
       "    }\n",
       "};\n",
       "                chart_feac788f158a4da09eae1076ca4fe21a.setOption(option_feac788f158a4da09eae1076ca4fe21a);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x2bba5cb8f28>"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m1=Map()\n",
    "m1.add(\"商家A\", data, \"浙江\",is_map_symbol_show=False)#注意这里城市的名称后面要加“市“\n",
    "m1.set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"Map-VisualMap（分段型）\"),\n",
    "            visualmap_opts=opts.VisualMapOpts(max_=3000, is_piecewise=True),\n",
    "        )\n",
    "m1.set_series_opts(label_opts=opts.LabelOpts(is_show=False))\n",
    "m1.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 基于百度api的地理可视化\n",
    "\n",
    "* 申请百度api的方法\n",
    "\n",
    "* 如果用老师的api，请勿滥用（短时间内多次频繁调用）导致此key被封,进而影响其他同学的学习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.globals import ChartType, SymbolType\n",
    "from pyecharts.charts import BMap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'bmap':'https://assets.pyecharts.org/assets/bmap.min', 'baidu_map_api62':'http://api.map.baidu.com/api?v=2.0&ak=K2n5m9GXasQFV5arkjpCGsXL', 'baidu_map_api68':'http://api.map.baidu.com/getscript?v=2.0&ak=K2n5m9GXasQFV5arkjpCGsXL'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"8a1cd555abc74b5aad96bb56b8f62448\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'bmap', 'baidu_map_api62', 'baidu_map_api68'], function(echarts) {\n",
       "                var chart_8a1cd555abc74b5aad96bb56b8f62448 = echarts.init(\n",
       "                    document.getElementById('8a1cd555abc74b5aad96bb56b8f62448'), 'white', {renderer: 'canvas'});\n",
       "                var option_8a1cd555abc74b5aad96bb56b8f62448 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"bmap\",\n",
       "            \"coordinateSystem\": \"bmap\",\n",
       "            \"symbolSize\": 12,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": [\n",
       "                        113.26653,\n",
       "                        23.132191,\n",
       "                        42\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": [\n",
       "                        116.407526,\n",
       "                        39.90403,\n",
       "                        59\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": [\n",
       "                        121.473701,\n",
       "                        31.230416,\n",
       "                        142\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": [\n",
       "                        115.909228,\n",
       "                        28.675696,\n",
       "                        63\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\",\n",
       "                    \"value\": [\n",
       "                        112.98381,\n",
       "                        28.112444,\n",
       "                        147\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": [\n",
       "                        120.152791,\n",
       "                        30.267446,\n",
       "                        60\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": [\n",
       "                        118.763232,\n",
       "                        32.061707,\n",
       "                        129\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"bmap\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"bmap\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": function (params) {        return params.name + ' : ' + params.value[2];    },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"BMap-\\u57fa\\u672c\\u793a\\u4f8b\"\n",
       "        }\n",
       "    ],\n",
       "    \"bmap\": {\n",
       "        \"center\": [\n",
       "            120.13066322374,\n",
       "            30.240018034923\n",
       "        ],\n",
       "        \"roam\": true\n",
       "    }\n",
       "};\n",
       "                chart_8a1cd555abc74b5aad96bb56b8f62448.setOption(option_8a1cd555abc74b5aad96bb56b8f62448);\n",
       "                    var bmap = chart_8a1cd555abc74b5aad96bb56b8f62448.getModel().getComponent('bmap').getBMap();\n",
       "                    bmap.addControl(new BMap.MapTypeControl());\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x28d18ac0ef0>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "BAIDU_AK = \"K2n5m9GXasQFV5arkjpCGsXL\"\n",
    "b1=BMap()\n",
    "b1.add_schema(\n",
    "            baidu_ak=BAIDU_AK,\n",
    "            center=[120.13066322374, 30.240018034923],\n",
    "        )\n",
    "b1.add(\n",
    "            \"bmap\",\n",
    "            [list(z) for z in zip(Faker.provinces, Faker.values())],\n",
    "            label_opts=opts.LabelOpts(formatter=\"{b}\"),\n",
    "        )\n",
    "b1.set_global_opts(title_opts=opts.TitleOpts(title=\"BMap-基本示例\"))\n",
    "b1.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 使用bmap做商品全国分布图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'bmap':'https://assets.pyecharts.org/assets/bmap.min', 'baidu_map_api62':'http://api.map.baidu.com/api?v=2.0&ak=K2n5m9GXasQFV5arkjpCGsXL', 'baidu_map_api68':'http://api.map.baidu.com/getscript?v=2.0&ak=K2n5m9GXasQFV5arkjpCGsXL'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"57fc1eb7ee904e5bbbd83984d356edcc\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'bmap', 'baidu_map_api62', 'baidu_map_api68'], function(echarts) {\n",
       "                var chart_57fc1eb7ee904e5bbbd83984d356edcc = echarts.init(\n",
       "                    document.getElementById('57fc1eb7ee904e5bbbd83984d356edcc'), 'white', {renderer: 'canvas'});\n",
       "                var option_57fc1eb7ee904e5bbbd83984d356edcc = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"bmap\",\n",
       "            \"coordinateSystem\": \"bmap\",\n",
       "            \"symbolSize\": 12,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": [\n",
       "                        121.473701,\n",
       "                        31.230416,\n",
       "                        154\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": [\n",
       "                        116.407526,\n",
       "                        39.90403,\n",
       "                        339\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5409\\u6797\",\n",
       "                    \"value\": [\n",
       "                        125.32599,\n",
       "                        43.896536,\n",
       "                        1\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u56db\\u5ddd\",\n",
       "                    \"value\": [\n",
       "                        104.075931,\n",
       "                        30.651651,\n",
       "                        4\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b89\\u5fbd\",\n",
       "                    \"value\": [\n",
       "                        117.284922,\n",
       "                        31.861184,\n",
       "                        24\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u4e1c\",\n",
       "                    \"value\": [\n",
       "                        117.020359,\n",
       "                        36.66853,\n",
       "                        44\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u897f\",\n",
       "                    \"value\": [\n",
       "                        112.562398,\n",
       "                        37.873531,\n",
       "                        39\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": [\n",
       "                        113.26653,\n",
       "                        23.132191,\n",
       "                        284\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": [\n",
       "                        118.763232,\n",
       "                        32.061707,\n",
       "                        120\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": [\n",
       "                        115.909228,\n",
       "                        28.675696,\n",
       "                        42\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\",\n",
       "                    \"value\": [\n",
       "                        114.468664,\n",
       "                        38.037057,\n",
       "                        86\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5357\",\n",
       "                    \"value\": [\n",
       "                        113.753602,\n",
       "                        34.765515,\n",
       "                        393\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": [\n",
       "                        120.152791,\n",
       "                        30.267446,\n",
       "                        2470\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5317\",\n",
       "                    \"value\": [\n",
       "                        114.341861,\n",
       "                        30.546498,\n",
       "                        27\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u798f\\u5efa\",\n",
       "                    \"value\": [\n",
       "                        119.295144,\n",
       "                        26.100779,\n",
       "                        952\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d35\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        106.70741,\n",
       "                        26.598194,\n",
       "                        2\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8fbd\\u5b81\",\n",
       "                    \"value\": [\n",
       "                        123.42944,\n",
       "                        41.835441,\n",
       "                        3\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91cd\\u5e86\",\n",
       "                    \"value\": [\n",
       "                        106.551556,\n",
       "                        29.563009,\n",
       "                        3\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"bmap\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"bmap\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": function (params) {        return params.name + ' : ' + params.value[2];    },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"BMap-\\u57fa\\u672c\\u793a\\u4f8b\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 3000,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true\n",
       "    },\n",
       "    \"bmap\": {\n",
       "        \"center\": [\n",
       "            120.13066322374,\n",
       "            30.240018034923\n",
       "        ],\n",
       "        \"roam\": true\n",
       "    }\n",
       "};\n",
       "                chart_57fc1eb7ee904e5bbbd83984d356edcc.setOption(option_57fc1eb7ee904e5bbbd83984d356edcc);\n",
       "                    var bmap = chart_57fc1eb7ee904e5bbbd83984d356edcc.getModel().getComponent('bmap').getBMap();\n",
       "                    bmap.addControl(new BMap.MapTypeControl());\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x28d18afc0f0>"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "BAIDU_AK = \"K2n5m9GXasQFV5arkjpCGsXL\"\n",
    "b1=BMap()\n",
    "b1.add_schema(\n",
    "            baidu_ak=BAIDU_AK,\n",
    "            center=[120.13066322374, 30.240018034923],\n",
    "        )\n",
    "b1.add(\n",
    "            \"bmap\",\n",
    "            [z for z in p0.items()],\n",
    "            label_opts=opts.LabelOpts(formatter=\"{b}\"),\n",
    "        )\n",
    "b1.set_global_opts(\n",
    "            visualmap_opts=opts.VisualMapOpts(is_piecewise=True,max_=3000),\n",
    "            title_opts=opts.TitleOpts(title=\"BMap-基本示例\"),\n",
    "        )\n",
    "b1.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 使用bmap做出浙江省的地市商品分布图\n",
    "\n",
    "* 注意调节中心点，和zoom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'bmap':'https://assets.pyecharts.org/assets/bmap.min', 'baidu_map_api62':'http://api.map.baidu.com/api?v=2.0&ak=K2n5m9GXasQFV5arkjpCGsXL', 'baidu_map_api68':'http://api.map.baidu.com/getscript?v=2.0&ak=K2n5m9GXasQFV5arkjpCGsXL'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"eb54881733f04214acc2064621fd08de\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'bmap', 'baidu_map_api62', 'baidu_map_api68'], function(echarts) {\n",
       "                var chart_eb54881733f04214acc2064621fd08de = echarts.init(\n",
       "                    document.getElementById('eb54881733f04214acc2064621fd08de'), 'white', {renderer: 'canvas'});\n",
       "                var option_eb54881733f04214acc2064621fd08de = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"bmap\",\n",
       "            \"coordinateSystem\": \"bmap\",\n",
       "            \"symbolSize\": 12,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u4e3d\\u6c34\",\n",
       "                    \"value\": [\n",
       "                        119.92,\n",
       "                        28.45,\n",
       "                        938\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u53f0\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        121.420757,\n",
       "                        28.656386,\n",
       "                        2\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5609\\u5174\",\n",
       "                    \"value\": [\n",
       "                        120.76,\n",
       "                        30.77,\n",
       "                        4\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b81\\u6ce2\",\n",
       "                    \"value\": [\n",
       "                        121.56,\n",
       "                        29.86,\n",
       "                        8\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u676d\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.19,\n",
       "                        30.26,\n",
       "                        107\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e29\\u5cad\",\n",
       "                    \"value\": [\n",
       "                        121.21,\n",
       "                        28.22,\n",
       "                        10\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e29\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.65,\n",
       "                        28.01,\n",
       "                        1275\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        120.1,\n",
       "                        30.86,\n",
       "                        118\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7ecd\\u5174\",\n",
       "                    \"value\": [\n",
       "                        120.58,\n",
       "                        30.01,\n",
       "                        1\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8862\\u5dde\",\n",
       "                    \"value\": [\n",
       "                        118.88,\n",
       "                        28.97,\n",
       "                        3\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91d1\\u534e\",\n",
       "                    \"value\": [\n",
       "                        119.64,\n",
       "                        29.12,\n",
       "                        4\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"bmap\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"bmap\": true\n",
       "            },\n",
       "            \"show\": true\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": function (params) {        return params.name + ' : ' + params.value[2];    },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"BMap-\\u57fa\\u672c\\u793a\\u4f8b\"\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 2000,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"bottom\": 50,\n",
       "        \"showLabel\": true\n",
       "    },\n",
       "    \"bmap\": {\n",
       "        \"center\": [\n",
       "            120.13066322374,\n",
       "            30.240018034923\n",
       "        ],\n",
       "        \"zoom\": 8,\n",
       "        \"roam\": true\n",
       "    }\n",
       "};\n",
       "                chart_eb54881733f04214acc2064621fd08de.setOption(option_eb54881733f04214acc2064621fd08de);\n",
       "                    var bmap = chart_eb54881733f04214acc2064621fd08de.getModel().getComponent('bmap').getBMap();\n",
       "                    bmap.addControl(new BMap.MapTypeControl());\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x28d1bbc7eb8>"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "BAIDU_AK = \"K2n5m9GXasQFV5arkjpCGsXL\"\n",
    "b1=BMap()\n",
    "b1.add_schema(\n",
    "            baidu_ak=BAIDU_AK,\n",
    "            center=[120.13066322374, 30.240018034923],zoom=8\n",
    "        )\n",
    "b1.add(\n",
    "            \"bmap\",\n",
    "            [z for z in p1.items()],\n",
    "            label_opts=opts.LabelOpts(formatter=\"{b}\"),\n",
    "        )\n",
    "b1.set_global_opts(\n",
    "            visualmap_opts=opts.VisualMapOpts(is_piecewise=True,max_=2000,pos_bottom=50),\n",
    "            title_opts=opts.TitleOpts(title=\"BMap-基本示例\"),\n",
    "        )\n",
    "b1.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课间题\n",
    "\n",
    " * 通过bmap，画出你家乡城市的地图，通过自定义坐标点，在家乡城市地图上画出你的家，小学，中学的位置，和任何你喜欢的地方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
